#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'

unordered_map<string, string> mp;
string change_a(string s) {
  string t = s;
  rep(i, 0, 3) swap(t[i], t[i + 4]);
  return t;
}
string change_b(string s) {
  string t = s;
  rep(i, 0, 3) {
    t[(i + 1) % 4] = s[i];
    t[4 + (i + 1) % 4] = s[i + 4];
  }
  return t;
}
string change_c(string s) {
  string t = s;
  t[1] = s[5];
  t[2] = s[1];
  t[6] = s[2];
  t[5] = s[6];
  return t;
}
void bfs(string s, string t) {
  queue<string> q;
  q.push(s);
  mp[s] = "";
  if (s == t) return;
  while (q.size()) {
    s = q.front();
    q.pop();
    string nxt[] = {change_a(s), change_b(s), change_c(s)};
    char ops[] = {'A', 'B', 'C'};
    rep(i, 0, 2) {
      string& cur = nxt[i];
      if (!mp.count(cur)) {
        q.push(cur);
        mp[cur] = mp[s] + ops[i];
      }
      if (cur == t) return;
    }
  }
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  string t, s = "12348765";
  rep(i, 0, 7) {
    char c;
    cin >> c;
    t.push_back(c);
  }
  reverse(t.begin() + 4, t.end());
  bfs(s, t);
  string ans = mp[t];
  int n = ans.size();
  cout << n << endl << ans;
  return 0;
}